package xyz.wanwanwan.www.hrm.fallbackfactory;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import xyz.wanwanwan.www.hrm.domain.CoursePromotion;
import xyz.wanwanwan.www.hrm.feign.client.CacheFeign;
import xyz.wanwanwan.www.hrm.util.AjaxResult;

@Component
@Slf4j
public class FeignClientFallbackFactory implements FallbackFactory<CacheFeign> {
    @Override
    public CacheFeign create(Throwable throwable) {
        return new CacheFeign() {
            @Override
            public AjaxResult setToRedis(String key, String value) {
                log.error("缓存失败了");
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("缓存失败");
            }

            @Override
            public AjaxResult savePromotion(CoursePromotion coursePromotion) {
                log.error("缓存失败了");
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("缓存促销失败了");
            }

            @Override
            public byte[] getBuyCoursePromotion(Long id) {
                log.error("下单促销失败了");
                throwable.printStackTrace();
                return null;
            }

            @Override
            public AjaxResult getListCoursePromotion() {
                log.error("获取缓存促销失败了");
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("获取缓存促销失败了");
            }


            @Override
            public AjaxResult getFromRedis(String key) {
                log.error("读取缓存失败了");
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("读取缓存失败");
            }

            @Override
            public AjaxResult delRedis(String key) {
                log.error("删除缓存失败了");
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("删除缓存失败");
            }

            @Override
            public AjaxResult setImageCodeToRedis(String key, int seconds, String value) {
                log.error("删除缓存失败了");
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("删除缓存失败");
            }
        };
    }
}
